/**
 * @FileName: MaintainQuestionElement.java
 * @Package: top.swimmer.demo.question
 * @author youshipeng
 * @created 2017/5/2 14:29
 * <p>
 * Copyright 2016 ziroom
 */
package top.swimmer.demo.question;

import java.util.ArrayList;
import java.util.List;

import static top.swimmer.tools.str.StringUtils.isEmpty;

/**
 * <p></p>
 *
 * <PRE>
 * <BR>	修改记录
 * <BR>-----------------------------------------------
 * <BR>	修改日期			修改人			修改内容
 * </PRE>
 *
 * @author youshipeng
 * @since 1.0
 * @version 1.0
 */
public class MaintainQuestionElement extends BaseQuestionElement {

    private List<QuestionElement> questionElements;

    public MaintainQuestionElement() {
        questionElements = new ArrayList<QuestionElement>() {{
            add(new QuestionElement(QuestionFocus.NAME));
            add(new QuestionElement(QuestionFocus.MOBILE));
            add(new QuestionElement(QuestionFocus.ADDRESS));
            add(new QuestionElement(QuestionFocus.MAINTAIN_THING));
        }};
    }

    public MaintainQuestionElement(String maintainTarget) {
        questionElements = new ArrayList<QuestionElement>() {{
            add(new QuestionElement(QuestionFocus.NAME));
            add(new QuestionElement(QuestionFocus.MOBILE));
            add(new QuestionElement(QuestionFocus.ADDRESS));
            add(new QuestionElement(QuestionFocus.MAINTAIN_THING, maintainTarget));
        }};
    }

    @Override
    public String beginAsk() {
        return "请问您需要报修吗？";
    }

    @Override
    public List<QuestionElement> getQuestionElements() {
        return questionElements;
    }

    @Override
    public String toString() {
        StringBuilder result = new StringBuilder("报修信息：{\n");
        for (QuestionElement element : questionElements) {
            if (!isEmpty(element.getValue())) {
                result.append("\t").append(element.getFocus().getTitle()).append(": ").append(element.getValue()).append("\n");
            }
        }
        return result + "}";
    }
}